package puzzle.sudoku.view.swing;

import java.awt.Color;
import java.awt.Graphics2D;

import puzzle.common.view.swing.AbstractPuzzleViewPanel;
import puzzle.sudoku.data.SudokuBoard;

public class SudokuViewPanel extends AbstractPuzzleViewPanel<SudokuBoard> {

	private static final long serialVersionUID = 1L;

	@Override
	protected void paintBoard(Graphics2D g2, SudokuBoard b) {
		for (int y = 0; y < b.height; y++) {
			for (int x = 0; x < b.width; x++) {
				int n = b.getNumber(x, y);

				if (n != 0) {
					if (b.isAssumed(x, y)) {
						g2.setColor(Color.RED);
					} else {
						g2.setColor(Color.BLACK);
					}
					drawStringInCell(g2, x, y, String.valueOf(n));
				}
			}
		}

		int sizeInPixels = m_cellSize * b.width;
		for (int i = 0; i <= b.width; i++) {
			int z = i * m_cellSize;
			if (i % b.base == 0) {
				g2.setStroke(m_lineStroke);
			} else {
				g2.setStroke(m_thinStroke);
			}
			g2.drawLine(z, 0, z, sizeInPixels);
			g2.drawLine(0, z, sizeInPixels, z);
		}
	}
}
